<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core">
    <ui:composition template="typetemplate.xhtml">
        <ui:define name="pageTitre">Détail Type</ui:define>
        <ui:define name="contenuTitre">Détail Type</ui:define>
        <ui:define name="content">
            <h:form  styleClass="jsfcrud_list_form">
                <h:inputHidden id="id" value="#{typeController.type.id}" />
                <c:set var="id" value="#{typeController.type.id}" />

                <h:outputText value="Nom" />
                <h:inputText id="name" value="#{typeController.type.name}"
                             required="true" requiredMessage="Nom obligatoire" />
                <h:message for="name" />

                <h:outputText value="Description" />
                <h:inputText id="description" value="#{typeController.type.description}"
                             required="true" requiredMessage="Description obligatoire" />
                <h:message for="description" />

                <h:outputText value="Super Type" />
                <h:selectOneMenu id="type" value="#{typeController.superTypeString}">
                    <f:selectItem itemValue="aucun" itemLabel="Aucun" />
                    <c:choose>
                        <c:when test="${id==null||id==0}">
                            <f:selectItems value="#{typeController.types}"
                                           var="type"
                                           itemValue="#{type.name}"
                                           itemLabel="#{type.name}" />
                        </c:when>
                        <c:otherwise>
                            <f:selectItems value="#{typeController.superTypes}"
                                           var="type"
                                           itemValue="#{type.name}"
                                           itemLabel="#{type.name}" />
                        </c:otherwise>
                    </c:choose>
                </h:selectOneMenu>
                <h:message for="type" />
                <br />
                <c:choose>
                    <c:when test="${id==null||id==0}">
                        <h:commandButton action="#{typeController.add}" value="Ajouter" />
                    </c:when>
                    <c:otherwise>
                        <h:dataTable var="row" value="#{typeController.type.pois}"  border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="POIs de ce type"/>
                                </f:facet>
                                <h:outputText value="#{row}" />
                            </h:column>
                        </h:dataTable>
                        <h:dataTable var="row" value="#{typeController.type.types}"  border="0" cellpadding="2" cellspacing="0" rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rules="all">
                            <h:column>
                                <f:facet name="header">
                                    <h:outputText value="Sous type de ce type"/>
                                </f:facet>
                                <h:outputText value="#{row}" />
                            </h:column>
                        </h:dataTable>
                        <h:commandButton action="#{typeController.update}" value="Modifier" />
                    </c:otherwise>
                </c:choose>
            </h:form>
        </ui:define>
    </ui:composition>
</html>